<template>
  <div class="friend-requests-container">
    <div class="friend-requests-header">
      <el-button icon="el-icon-arrow-left" @click="goBack">返回</el-button>
      <h1>好友请求</h1>
    </div>
    
    <div class="friend-requests-content">
      <div v-if="friendRequests.length === 0" class="no-requests">
        <p>暂无好友请求</p>
      </div>
      
      <div v-else class="requests-list">
        <div class="request-item" v-for="request in friendRequests" :key="request.id">
          <img :src="request.avatar" :alt="request.name" class="request-avatar" />
          <div class="request-info">
            <div class="request-name">{{ request.name }}</div>
            <div class="request-message">{{ request.message }}</div>
            <div class="request-time">{{ request.time }}</div>
          </div>
          <div class="request-actions">
            <el-button type="primary" size="small" @click="acceptRequest(request)">接受</el-button>
            <el-button size="small" @click="rejectRequest(request)">拒绝</el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "FriendRequests",
  data() {
    return {
      friendRequests: [
        { id: 1, name: "李明", message: "我是你的同学，想加你为好友", avatar: require('@/assets/default-avatar.png'), time: "2024-01-15 14:30" },
        { id: 2, name: "王芳", message: "你好，我们是同事", avatar: require('@/assets/default-avatar.png'), time: "2024-01-14 10:20" },
        { id: 3, name: "张伟", message: "通过群聊认识你，希望能加个好友", avatar: require('@/assets/default-avatar.png'), time: "2024-01-13 16:45" }
      ]
    };
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    
    acceptRequest(request) {
      this.$confirm(`确定要接受 ${request.name} 的好友请求吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 模拟接受好友请求
        this.$message.success(`已接受 ${request.name} 的好友请求`);
        // 从列表中移除该请求
        this.friendRequests = this.friendRequests.filter(r => r.id !== request.id);
      }).catch(() => {
        // 用户取消操作
      });
    },
    
    rejectRequest(request) {
      this.$confirm(`确定要拒绝 ${request.name} 的好友请求吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 模拟拒绝好友请求
        this.$message.success(`已拒绝 ${request.name} 的好友请求`);
        // 从列表中移除该请求
        this.friendRequests = this.friendRequests.filter(r => r.id !== request.id);
      }).catch(() => {
        // 用户取消操作
      });
    }
  }
};
</script>

<style scoped>
.friend-requests-container {
  padding: 20px;
  height: 100%;
  overflow-y: auto;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
}

.friend-requests-header {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.friend-requests-header h1 {
  margin: 0 0 0 20px;
  font-size: 24px;
  color: #333;
}

.friend-requests-content {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 15px;
  padding: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
}

.no-requests {
  text-align: center;
  padding: 50px 0;
  color: #999;
}

.request-item {
  display: flex;
  align-items: center;
  padding: 15px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.request-item:last-child {
  border-bottom: none;
}

.request-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  margin-right: 15px;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.request-info {
  flex: 1;
}

.request-name {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  margin-bottom: 5px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.request-message {
  font-size: 14px;
  color: #666;
  margin-bottom: 5px;
  background: rgba(255, 255, 255, 0.3);
  padding: 8px 12px;
  border-radius: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.request-time {
  font-size: 12px;
  color: #666;
  font-style: italic;
}

.request-actions {
  display: flex;
  gap: 10px;
}

.request-actions .el-button {
  background: rgba(255, 255, 255, 0.3);
  border: none;
  color: #333;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.request-actions .el-button:hover {
  background: rgba(255, 255, 255, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.request-actions .el-button--primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

/* 移动端优化 */
@media (max-width: 767px) {
  .friend-requests-container {
    padding: var(--spacing-sm);
  }
  
  .friend-requests-header {
    margin-bottom: var(--spacing-sm);
  }
  
  .friend-requests-header h1 {
    font-size: 20px;
    margin-left: var(--spacing-sm);
  }
  
  .friend-requests-content {
    padding: var(--spacing-sm);
  }
  
  .no-requests {
    padding: var(--spacing-xl) 0;
  }
  
  .request-item {
    flex-direction: column;
    align-items: flex-start;
    padding: var(--spacing-sm) 0;
  }
  
  .request-avatar {
    width: 40px;
    height: 40px;
    margin-right: 0;
    margin-bottom: var(--spacing-sm);
  }
  
  .request-info {
    width: 100%;
    margin-bottom: var(--spacing-sm);
  }
  
  .request-name {
    font-size: 15px;
    margin-bottom: var(--spacing-xs);
  }
  
  .request-message {
    font-size: 13px;
    margin-bottom: var(--spacing-xs);
  }
  
  .request-time {
    font-size: 11px;
  }
  
  .request-actions {
    align-self: flex-end;
  }
  
  .request-actions .el-button {
    font-size: 12px;
    padding: 4px 8px;
  }
}
</style>